<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Execute a prepared SQL statement</title>
 </head>
 <body class="docs"><div id="layout">
  <div id="layout-content"><div id="function.cubrid-execute" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">cubrid_execute</h1>
  <p class="verinfo">(PECL CUBRID &gt;= 8.3.0)</p><p class="refpurpose"><span class="refname">cubrid_execute</span> &mdash; <span class="dc-title">Execute a prepared SQL statement</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-function.cubrid-execute-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>cubrid_execute</strong></span>
    ( <span class="methodparam"><span class="type">resource</span> <code class="parameter">$conn_identifier</code></span>  
   , <span class="methodparam"><span class="type">string</span> <code class="parameter">$sql</code></span>  
   [, <span class="methodparam"><span class="type">int</span> <code class="parameter">$option</code><span class="initializer"> = 0</span></span>  
  ] ) : <span class="type">resource</span></div>

  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>cubrid_execute</strong></span>
    ( <span class="methodparam"><span class="type">resource</span> <code class="parameter">$request_identifier</code></span>  
   [, <span class="methodparam"><span class="type">int</span> <code class="parameter">$option</code><span class="initializer"> = 0</span></span>  
  ] ) : <span class="type">bool</span></div>

    <p class="para rdfs-comment">
      The <span class="function"><strong>cubrid_execute()</strong></span> function is used to execute the
      given SQL statement. It executes the query by using
      <code class="parameter">conn_identifier</code> and SQL, and then returns the
      request identifier created. It is used for simple execution of query,
      where the parameter binding is not needed. In addition, the
      <span class="function"><strong>cubrid_execute()</strong></span> function is used to execute the
      prepared statement by means of <span class="function"><a href="cubrid_prepare.html" class="function">cubrid_prepare()</a></span> and
      <span class="function"><a href="cubrid_bind.html" class="function">cubrid_bind()</a></span>. At this time, you need to specify
      arguments of <code class="parameter">request_identifier</code> and
      <code class="parameter">option</code>.
    </p>
    <p class="para">
     The <code class="parameter">option</code> is used to determine whether to get OID
     after query execution and whether to execute the query in synchronous or
     asynchronous mode. CUBRID_INCLUDE_OID and CUBRID_ASYNC (or
     CUBRID_EXEC_QUERY_ALL if you want to execute multiple SQL statements) can
     be specified by using a bitwise OR operator. If not specified, neither of
     them isselected. If the flag CUBRID_EXEC_QUERY_ALL is set, a synchronous
     mode (sync_mode) is used to retrieve query results, and in such cases the
     following rules are applied: 
    </p>
    <p class="para">
     <ul class="simplelist">
      <li class="member">The return value is the result of the first query.</li>
      <li class="member">
       If an error occurs in any query, the execution is processed as a
       failure.
      </li>
      <li class="member">
       In a query composed of q1 q2 q3, if an error
       occurs in q2 after q1 succeeds the execution, the result of q1 remains
       valid. That is, the previous successful query executions are not rolled
       back when an error occurs.
      </li>
      <li class="member">
       If a query is executed successfully, the result of the second query can
       be obtained using <span class="function"><a href="cubrid_next_result.html" class="function">cubrid_next_result()</a></span>.
      </li>
     </ul>
    </p>
    <p class="para">
     If the first argument is <code class="parameter">request_identifier</code> to
     execute the <span class="function"><a href="cubrid_prepare.html" class="function">cubrid_prepare()</a></span> function, you can specify
     an option, CUBRID_ASYNC only.
    </p>
 </div>


  <div class="refsect1 parameters" id="refsect1-function.cubrid-execute-parameters">
 <h3 class="title">参数</h3>
 <p class="para">
      <dl>

        
      <dt>
<code class="parameter">conn_identifier</code></dt>

      <dd>
<p class="para">Connection identifier.</p></dd>

       
       
      <dt>
<code class="parameter">sql</code></dt>

      <dd>
<p class="para">SQL to be executed.</p></dd>

       
       
      <dt>
<code class="parameter">option</code></dt>

      <dd>
<p class="para">Query execution option CUBRID_INCLUDE_OID, CUBRID_ASYNC, CUBRID_EXEC_QUERY_ALL.</p></dd>

       
        
      <dt>
<code class="parameter">request_identifier</code></dt>

      <dd>
<p class="para"><span class="function"><a href="cubrid_prepare.html" class="function">cubrid_prepare()</a></span> identifier.</p></dd>

       
      </dl>

  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.cubrid-execute-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
    Request identifier, when process is successful and first param is
    conn_identifier; <strong><code>TRUE</code></strong>, when process is successful and first argument is
    request_identifier.
  </p>
  <p class="para">
    <strong><code>FALSE</code></strong>, when process is unsuccessful.
  </p>
 </div>


 <div class="refsect1 changelog" id="refsect1-function.cubrid-execute-changelog">
  <h3 class="title">更新日志</h3>
  <p class="para">
   <table class="doctable informaltable">
    
     <thead>
      <tr>
       <th>版本</th>
       <th>说明</th>
      </tr>

     </thead>

     <tbody class="tbody">
      <tr>
       <td>8.4.0</td>
       <td>
        Add new option CUBRID_EXEC_QUERY_ALL.
       </td>
      </tr>

     </tbody>
    
   </table>

  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.cubrid-execute-examples">
  <h3 class="title">范例</h3>
  <div class="example" id="example-1107">
   <p><strong>Example #1 <span class="function"><strong>cubrid_execute()</strong></span> example</strong></p>
   <div class="example-contents">
<div class="phpcode"><pre><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$conn&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">cubrid_connect</span><span style="color: #007700">(</span><span style="color: #DD0000">"localhost"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">33000</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"demodb"</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$result&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">cubrid_execute</span><span style="color: #007700">(</span><span style="color: #0000BB">$conn</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"SELECT&nbsp;code&nbsp;FROM&nbsp;event&nbsp;WHERE&nbsp;name='100m&nbsp;Butterfly'&nbsp;and&nbsp;gender='M'"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">CUBRID_ASYNC</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$row&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">cubrid_fetch_array</span><span style="color: #007700">(</span><span style="color: #0000BB">$result</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">CUBRID_ASSOC</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$event_code&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$row</span><span style="color: #007700">[</span><span style="color: #DD0000">"code"</span><span style="color: #007700">];<br /><br /></span><span style="color: #0000BB">cubrid_close_request</span><span style="color: #007700">(</span><span style="color: #0000BB">$result</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$history_req&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">cubrid_prepare</span><span style="color: #007700">(</span><span style="color: #0000BB">$conn</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"SELECT&nbsp;*&nbsp;FROM&nbsp;history&nbsp;WHERE&nbsp;event_code=?"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">cubrid_bind</span><span style="color: #007700">(</span><span style="color: #0000BB">$history_req</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">1</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$event_code</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"number"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">cubrid_execute</span><span style="color: #007700">(</span><span style="color: #0000BB">$history_req</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">printf</span><span style="color: #007700">(</span><span style="color: #DD0000">"%-20s&nbsp;%-9s&nbsp;%-10s&nbsp;%-5s\n"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"athlete"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"host_year"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"score"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"unit"</span><span style="color: #007700">);<br />while&nbsp;(</span><span style="color: #0000BB">$row&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">cubrid_fetch_array</span><span style="color: #007700">(</span><span style="color: #0000BB">$history_req</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">CUBRID_ASSOC</span><span style="color: #007700">))&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">printf</span><span style="color: #007700">(</span><span style="color: #DD0000">"%-20s&nbsp;%-9s&nbsp;%-10s&nbsp;%-5s\n"</span><span style="color: #007700">,&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$row</span><span style="color: #007700">[</span><span style="color: #DD0000">"athlete"</span><span style="color: #007700">],&nbsp;</span><span style="color: #0000BB">$row</span><span style="color: #007700">[</span><span style="color: #DD0000">"host_year"</span><span style="color: #007700">],&nbsp;</span><span style="color: #0000BB">$row</span><span style="color: #007700">[</span><span style="color: #DD0000">"score"</span><span style="color: #007700">],&nbsp;</span><span style="color: #0000BB">$row</span><span style="color: #007700">[</span><span style="color: #DD0000">"unit"</span><span style="color: #007700">]);<br />}<br /><br /></span><span style="color: #0000BB">cubrid_close_request</span><span style="color: #007700">(</span><span style="color: #0000BB">$history_req</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">cubrid_disconnect</span><span style="color: #007700">(</span><span style="color: #0000BB">$conn</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</pre></div>
   </div>

    <div class="example-contents"><p>以上例程会输出：</p></div>
    <div class="example-contents screen">
<div class="cdata"><pre>
athlete              host_year score      unit 
Phelps Michael       2004      51.25      time 
</pre></div>
   </div>
  </div>
 </div>


   <div class="refsect1 seealso" id="refsect1-function.cubrid-execute-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
   <li class="member"><span class="function"><a href="cubrid_prepare.html" class="function" rel="rdfs-seeAlso">cubrid_prepare()</a> - Prepare a SQL statement for execution</span></li>
   <li class="member"><span class="function"><a href="cubrid_bind.html" class="function" rel="rdfs-seeAlso">cubrid_bind()</a> - Bind variables to a prepared statement as parameters</span></li>
   <li class="member"><span class="function"><a href="cubrid_next_result.html" class="function" rel="rdfs-seeAlso">cubrid_next_result()</a> - Get result of next query when executing multiple SQL statements</span></li>
   <li class="member"><span class="function"><a href="cubrid_close_request.html" class="function" rel="rdfs-seeAlso">cubrid_close_request()</a> - Close the request handle</span></li>
   <li class="member"><span class="function"><a href="cubrid_commit.html" class="function" rel="rdfs-seeAlso">cubrid_commit()</a> - Commit a transaction</span></li>
   <li class="member"><span class="function"><a href="cubrid_rollback.html" class="function" rel="rdfs-seeAlso">cubrid_rollback()</a> - Roll back a transaction</span></li>
   </ul>
  </p>
  </div>


</div></div></div></body></html>